package com.hh.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hh.commonutils.Result;
import com.hh.commonutils.jwt.JwtUtil;
import com.hh.eduservice.entity.EduCourse;
import com.hh.eduservice.entity.vo.CourseVo;
import com.hh.eduservice.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@RestController
@RequestMapping("eduservice/coursefront")
public class FrontEduCourseController {
    @Autowired
    private EduCourseService eduCourseService;

    @PostMapping("getFrontCourseList/{page}/{limit}")
    public Result getFrontCourseList(@PathVariable long page,@PathVariable long limit,@RequestBody CourseVo searchObject){
        Page<EduCourse> pageParam = new Page<>(page,limit);
        HashMap map = eduCourseService.getFrontCourseList(pageParam,searchObject);
        return Result.success().data(map);
    }

    @GetMapping("getFrontCourseInfo/{id}")
    public Result getCourseInfo(@PathVariable String id, HttpServletRequest request){
        HashMap map = eduCourseService.getCourseById(id, JwtUtil.getMemberIdByJwtToken(request));
        return Result.success().data(map);
    }
}
